package com.gxuwz.xmlrw;

import java.io.File;  
import javax.xml.parsers.DocumentBuilder;  
import javax.xml.parsers.DocumentBuilderFactory;  
import org.w3c.dom.Document;  
import org.w3c.dom.Node;  

public class DomReader {
    public static void main(String args[])throws Exception{  
        //创建文件解析工厂  
        DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();  
  
  
        //使用工厂创建文件解析类  
        DocumentBuilder builder = dfactory.newDocumentBuilder();  
  
  
        //开始解析文件，将文件加载进内存，形成dom树  
        Document document = builder.parse(new File("test.xml"));  
          
          
        //获取根节点并打印出来  
        Node rootn = document.getFirstChild();  
        System.out.println(rootn.getNodeName());  
    }  
}
